<?php


namespace app\agent\controller;

class Index extends AdminBase
{
	public function get_app_list()
	{
		$where = [];
		$options = $this->request->get();
		$binding_appids = \think\Db::name("app_agent_binding")->where(["agent_id" => $this->admin_info["id"]])->column("appid");
		$apps = \think\Db::name("app")->whereIn("id", $binding_appids)->field("id,name,avatar,type,cid")->order(["sort" => "desc", "id" => "asc"])->select();
		$classify_ids = [];
		foreach ($apps as $app) {
			$classify_ids[] = $app["cid"];
		}
		if (!empty($options["cid"])) {
			$apps = \think\Db::name("app")->whereIn("id", $binding_appids)->where(["cid" => $options["cid"]])->field("id,name,avatar,type,cid")->order(["sort" => "desc", "id" => "asc"])->select();
		}
		$classify_ids = array_unique($classify_ids);
		$classify_list = \think\Db::name("app_classify")->whereIn("id", $classify_ids)->field("id,name")->order(["sort" => "desc", "id" => "asc"])->select();
		$this->response(\app\agent\model\Code::success, "获取成功", ["classify" => $classify_list, "list" => $apps]);
	}
	public function get_app_data($appid)
	{
		$options = ["appid" => $appid, "id" => $this->admin_info["id"]];
		$result = \app\agent\service\AgentService::get_app_data($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_self_info()
	{
		$data = ["id" => $this->admin_info["id"], "name" => $this->admin_info["name"], "account" => $this->admin_info["account"], "money" => $this->admin_info["money"], "create_time" => $this->admin_info["create_time"], "login_time" => $this->admin_info["login_time"], "login_ip" => $this->admin_info["login_ip"], "qq" => $this->admin_info["qq"], "add_subordinate_authority" => $this->admin_info["add_subordinate_authority"], "divide_subordinate_add_subordinate_authority" => $this->admin_info["divide_subordinate_add_subordinate_authority"], "app_auth_total" => \think\Db::name("app_agent_binding")->where(["agent_id" => $this->admin_info["id"]])->count(), "subordinate_count" => \think\Db::name("app_agent")->where(["superior_id" => $this->admin_info["id"]])->count()];
		$this->response(\app\agent\model\Code::success, "获取成功", $data);
	}
}